//
//  ZJStudySpecialDetailTableViewCell.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJStudySpecialDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
@interface ZJStudySpecialDetailTableViewCell ()
/** 图片 */
@property (nonatomic, strong) UIImageView *imageview;
/** 题目 */
@property (nonatomic, strong) UILabel *titleLabel;
/** 时长 */
@property (nonatomic, strong) UILabel *time;
/** 评分 */
@property (nonatomic, strong) UILabel *grade;
/** 分割线 */
@property (nonatomic, strong) UILabel *underline;
@end

@implementation ZJStudySpecialDetailTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.imageview];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.time];
        [self.contentView addSubview:self.grade];
        [self.contentView addSubview:self.underline];
        
        self.underline.sd_layout
        .bottomSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(7.5 * [UIScreen zj_screenHScale]);
        
        self.imageview.sd_layout
        .topSpaceToView(self.contentView, 12 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .bottomSpaceToView(self.underline, 12 * [UIScreen zj_screenHScale])
        .widthIs(140 * [UIScreen zj_screenWScale]);
        
        
        self.titleLabel.sd_layout
        .topEqualToView(self.imageview)
        .leftSpaceToView(self.imageview, 8.5 * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - (140 + 12 + 12 + 8.5) * [UIScreen zj_screenWScale])
        .heightIs(46 * [UIScreen zj_screenHScale]);
        
        self.grade.sd_layout
        .bottomEqualToView(self.imageview)
        .leftEqualToView(self.titleLabel)
        .rightEqualToView(self.titleLabel)
        .heightIs([NSString heightWithTextFontSize:[UIFont subTitleTextFontSize]]);
        
        self.time.sd_layout
        .bottomSpaceToView(self.grade, 7 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.grade)
        .rightEqualToView(self.grade)
        .heightRatioToView(self.grade, 1);
        
    }
    return self;
}



#pragma mark - Setter
- (void)setModel:(ZJStudySpacialDetailModel *)model{
    _model = model;
    [self.imageview sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL ,model.IMAGEPHOTO_THUMBURL]] placeholderImage:PlaceholderImage];
    self.titleLabel.text = model.NAME;
//    [self.titleLabel setLabelSpace:4 * [UIScreen zj_screenHScale]];
    
    self.titleLabel.sd_layout
    .topEqualToView(self.imageview)
    .leftSpaceToView(self.imageview, 8.5 * [UIScreen zj_screenWScale])
    .widthIs([UIScreen zj_screenWith] - (140 + 12 + 12 + 8.5) * [UIScreen zj_screenWScale])
    .heightIs([self.titleLabel getSpaceLabelHeightFromSpace:4 * [UIScreen zj_screenHScale]]);
    [self.titleLabel updateLayout];
    
    NSString *timeTest = [NSString stringWithFormat:@"时长 : %@  (%@%%)",[NSString getTimeLabelValues:[model.DURATION doubleValue]],model.PLAYPERCENTAGE ? model.PLAYPERCENTAGE : @"0"];

    self.time.text = timeTest;
    self.grade.text = [NSString stringWithFormat:@"评分 : %@",model.GRADE];
    
}

#pragma mark - Getters

- (UIImageView *)imageview{
    if (_imageview == nil){
        _imageview = [UIImageView new];
        _imageview.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    return _imageview;
}


- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor textBlackColor];
        _titleLabel.font = [UIFont titleTextFont];
        _titleLabel.numberOfLines = 2;
    }
    return _titleLabel;
}

- (UILabel *)time{
    if (_time == nil){
        _time = [UILabel new];
        _time.textColor = [UIColor textGrayColor];
        _time.font = [UIFont subTitleTextFont];
        
    }
    return _time;
}
- (UILabel *)grade{
    if (_grade == nil){
        _grade = [UILabel new];
        _grade.textColor = [UIColor textGrayColor];
        _grade.font = [UIFont subTitleTextFont];
    }
    return _grade;
}

- (UILabel *)underline{
    if (_underline == nil){
        _underline = [UILabel new];
        _underline.backgroundColor = [UIColor viewBGGrayColor];
    }
    return _underline;
}

@end
